<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>添加公告信息</title>
<style>
#imgDiv div{
	margin-left:8px;
	margin-top:8px;
	position:relative;
}
.del-img{
	position:absolute;
	left:0px;
	top:0px;
	z-index:9999;
	cursor:pointer;
	display:none;
}
.gray {
	filter: grayscale(100%);
	-webkit-filter: grayscale(100%);
	-moz-filter: grayscale(100%);
	-ms-filter: grayscale(100%);
	-o-filter: grayscale(100%);
	filter: url(desaturate.svg#grayscale);
	filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
	-webkit-filter: grayscale(1);
}
</style>
</head>

<body>
	<div class="container-fluid">
		<div class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">系统公告</a> <span class="divider">/</span></li>
					<li><a href="#">公告信息</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-edit"></i> 添加公告信息
					</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<form id="myform" class="form-horizontal" method="post"
						action="<c:url value="/admin/news/reportInfo" />">
						<fieldset>
							<div class="top-pills">
								<div class="tabbable">
									<!-- Only required for left/right tabs -->
									<ul class="nav nav-tabs">
										<li class="active"><a href="#tab1" data-toggle="tab">基本信息</a></li>
										<li><a href="#tab2" data-toggle="tab">详细信息</a></li>
									</ul>
									<div class="tab-content">
										<div class="tab-pane active" id="tab1">
											<input type="hidden" name="newsId" value="${news.newsId }">
											<div class="control-group">
												<label class="control-label" for="sortId">分类</label>
												<div class="controls">
													<select id="sortId" name="sortId" class="input-xlarge"
														name="liveSorts">
														<c:forEach var="sort" items="${sorts }">
															<option value="${sort.sortId }"
																<c:if test='${sort.sortId == news.sortId }'>selected</c:if>>${sort.sortName
																}</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="title">标题</label>
												<div class="controls">
													<input class="input-xlarge focused" name="newsTitle"
														check-type="required" required-message="请输入标题" id="title"
														type="text" value="${news.newsTitle }" maxlength="100">
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="news">作者 </label>
												<div class="controls">
													<input class="input-xlarge" name="author" id="author"
														check-type="required" required-message="请输入作者" type="text"
														value="${news.author }">
												</div>
											</div>
											

											<div class="control-group">
												<label class="control-label" for="newsDesc">公告简介 </label>
												<div class="controls">
													<textarea rows="3" name="newsDesc" class="input-xlarge">${news.newsDesc }</textarea>
												</div>
											</div>

											<div class="control-group">
												<label class="control-label" for="fileInput">上传缩略图</label>
												<div class="controls">
													<input class="input-file uniform_on" name="file"
														id="userHeader" type="file"> <input type="button"
														value="upload" onclick="return ajaxFileUpload();">
												</div>
												
											</div>
											<div class="control-group">
												<div class="controls">
													<img id="loading" class="hide"
													src="<c:url value="/resources/img/ajax-loader-6.gif"/>">
												<img id="picture"
													src='<c:url value="/resources/fileupload/${news.newsLogo }"/>'
													height="100"> <input type="hidden" name="newsLogo"
													id="newsLogo" value="${news.newsLogo }">
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="fileInput">上传图片</label>
												<div class="controls">
													<input class="input-file uniform_on" name="file"
														id="files" type="file"> <input type="button" class="btn btn-success"
														value="upload" onclick="return ajaxFileUpload_files();">
													<img id="loading2" class="hide" src="<c:url value="/resources/img/ajax-loader-6.gif"/>">
												</div>
											</div>
											<div class="control-group">
													
												<label class="control-label" for="fileInput">&nbsp;</label>
												<div class="controls" id="imgDiv">
													
												</div>
											</div>
											
											
											<div class="control-group">
												<label class="control-label" for="commentBaseCount">评论基数</label>
												<div class="controls">
													<input class="input-xlarge" id="commentBaseCount"
														name="commentBaseCount" type="text"
														value="${news.commentBaseCount }" check-type="number">
												</div>
											</div>

											<input name="commentCount" type="hidden"
												value="${news.commentCount }"> <input
												name="praiseCount" type="hidden"
												value="${news.praiseCount }">

											<div class="control-group">
												<label class="control-label" for="praiseBaseCount">点赞基数</label>
												<div class="controls">
													<input class="input-xlarge" id="praiseBaseCount"
														name="praiseBaseCount" type="text"
														value="${news.praiseBaseCount }" check-type="number">
												</div>
											</div>
											<div class="control-group">
												<label class="control-label" for="views">浏览数</label>
												<div class="controls">
													<input class="input-xlarge" id="views"
														name="views" type="text"
														value="${news.views }" check-type="number">
												</div>
											</div>
											<div class="control-group" id="showInIndex">
												<label class="control-label" for="showInIndex">是否显示在首页</label>
												<div class="controls">
													<label class="radio inline"> 
														<input type="radio" name="showInIndex" value="1" <c:if test="${news.showInIndex == 1 }">checked</c:if>>是
													</label> 
													<label class="radio inline"> 
														<input type="radio" name="showInIndex" value="0" <c:if test="${news.showInIndex == 0 }">checked</c:if>>否
													</label>
												</div>
											</div>
										</div>
										<div class="tab-pane" id="tab2">
											<div class="control-group">
												<label class="control-label" for="newsDetails">详细描述</label>
												<div class="controls">
													<textarea id="newsDetails" name="newsDetails" rows="18"
														style="height:500px;width: 90%" class="">${news.newsDetails }</textarea>
												</div>
											</div>
											
										</div>
										
									</div>
								</div>
							</div>

							<div class="form-actions">
								<input type="hidden" name="newsImages" id="images" value="${news.newsImages }">		
								<button id="saveBtn" type="button" class="btn btn-primary">保存</button>
								<button id="cancelBtn" type="button" class="btn">返回</button>
							</div>
						</fieldset>
					</form>

				</div>
			</div>
			<!--/span-->

		</div>
	</div>
	<!--/row-->
</body>

<jsp:include page="../frame/scripts.jsp"></jsp:include>
<script type="text/javascript">
	var images = new Array();
	
	$(document).ready(function() {
		
		$('#cancelBtn').click(function() {
				window.location.href = '<c:url value="/admin/news/reportInfo" />';
		})


		$("#myform").validation();
		
		var imgs = "${news.newsImages}";
		if(imgs && "" != imgs){
			$.each(imgs.split(","),function(i,item){
				setImages(item);
			})
		}


		//保存
		$('#saveBtn').click(function() {
			if ($("#sortId").val() == null) {
				alert("请首先创建属于地址类信息的分类！");
				return;
			}
			
			var value = images.join(",");
			$("input[name='newsImages']").val(value);
			
			$("#myform").submit();
		})

		//xheditor 文件上传
		$('#newsDetails').xheditor({
			tools:'full',
			skin:'default',
			upMultiple:1,
			html5Upload:false,
			upImgUrl:'<c:url value="/xheditor/fileupload"/>',
			upImgExt:'jpg,png,jpeg,gif,bmp',
			onUpload:function(data){
				
			}
		})
						
						

})

	//上传图片
	function ajaxFileUpload() {

		$("#loading").ajaxStart(function() {
			//开始上传文件时显示一个图片
			$(this).show();
		}).ajaxComplete(function() {
			//文件上传完成将图片隐藏起来
			$(this).hide();
		});

		$.ajaxFileUpload({
			url : '<c:url value="/fileupload"/>',//用于文件上传的服务器端请求地址
			secureuri : false,//一般设置为false
			fileElementId : 'userHeader',//文件上传空间的id属性  <input type="file" id="file" name="file" />
			dataType : 'JSON',//返回值类型 一般设置为json(大写)
			success : function(data, status) {
				var image = DOMAIN + '/resources/fileupload/' + $(data).html();
				$("#picture").attr('src', image).show();
				$("input[name='newsLogo']").val($(data).html());
			},
			error : function(data, status, e) {
				alert(e);
			}
		})

		return false;
	}
	
	function setImages(item){
		var image = DOMAIN + '/resources/fileupload/'+item;
		var delImg = '<c:url value="/resources/img/del.png"/>';
		var img = '<div style="float:left;height:100px;" onmouseout="hideClose()" onmouseover="showClose(this)"><img class="del-img" onclick="delImg(this,\''+item+'\')" src="'+delImg+'"><img class="pic" src="'+image+'" height="100"></div>';
		$("#imgDiv").append(img).show();
		images.push(item);	
	}

	//上传图片
	function ajaxFileUpload_files(){
		
		$("#loading2").ajaxStart(function(){
			//开始上传文件时显示一个图片
			$(this).show();
		}).ajaxComplete(function(){
			//文件上传完成将图片隐藏起来
			$(this).hide();
		});
		
		$.ajaxFileUpload({
			url:'<c:url value="/fileupload"/>',//用于文件上传的服务器端请求地址
			secureuri:false,//一般设置为false
			fileElementId:'files',//文件上传空间的id属性  <input type="file" id="file" name="file" />
			dataType: 'JSON',//返回值类型 一般设置为json(大写)
			success: function (data, status){
				setImages($(data).html());
			},
			error: function (data, status, e){
				alert(e);
			}	
		})
		
		return false;
	}

	function showClose(obj){
		$(".del-img").hide();
		$(".pic").removeClass("gray");
		$(obj).find(".pic").addClass("gray");
		$(obj).find(".del-img").show();
	}

	function delImg(obj,value){
		$(obj).parent().remove();
		var index = $.inArray(value,images);
		images.splice(index,1);
	}

	function hideClose(){
		$(".del-img").hide();
		$(".pic").removeClass("gray");
	}
	
	
</script>